/**
 * 
 */
package fr.gfi.agraf.vue.action.ajax;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;

import fr.gfi.agraf.service.INotificationService;
import fr.gfi.agraf.utils.SpringFactory;
import fr.gfi.agraf.vue.action.login.LoginAction;
import fr.gfi.agraf.vue.bean.UtilisateurDTO;

/**
 * @author Fw
 * 
 */
public class AjaxMarquerNotifsVues extends ActionSupport implements SessionAware {

	/**
	 * Généré par Java
	 */
	private static final long serialVersionUID = 4136272650020985174L;

	private static final String NOTIFICATION_SERVICE = "NotificationService";

	private Map<String, Object> session;

	private boolean transmis;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	@Override
	public String execute() {
		final UtilisateurDTO userConnected = (UtilisateurDTO) session.get(LoginAction.UTILISATEUR);

		if (userConnected != null) {
			final INotificationService notificationService = (INotificationService) SpringFactory
					.getApplicationContext().getBean(NOTIFICATION_SERVICE);
			notificationService.marqueesToutesNotifsVuesByUtilisateur(userConnected.getId());
			transmis = true;
		} else {
			transmis = false;
		}

		return SUCCESS;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.apache.struts2.interceptor.SessionAware#setSession(java.util.Map)
	 */
	public void setSession(final Map<String, Object> session) {
		this.session = session;
	}

	/**
	 * @return the transmis
	 */
	public boolean isTransmis() {
		return transmis;
	}

}
